{% extends 'layout/base.html' %}

{% block content %}
<div class="row mt-5">
    <div class="col-lg-3">
        {% set active_nav = 'smtp' %}
        {% include 'config/includes/sidebar.html' %}
    </div>
    <div class="col-lg-5">
        <h4>SMTP Settings</h4>

        <form action="{{ url_for('config.smtp_save') }}" method="post">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_enabled">Enable SMTP Notifications</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="smtp_enabled" type="checkbox" class="custom-control-input" id="smtp_enabled" value="1" {{ 'checked' if setting_get('smtp_enabled', False) == True }}>
                        <label class="custom-control-label" for="smtp_enabled"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_host">SMTP Host</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="smtp_host" id="smtp_host" value="{{ setting_get('smtp_host', '') }}" placeholder="" required>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_port">SMTP Port</label>
                </div>
                <div class="col">
                    <input type="number" class="form-control text-right hide-spin-buttons" name="smtp_port" id="smtp_port" value="{{ setting_get('smtp_port', '') }}" placeholder="" required>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_tls">TLS</label>
                </div>
                <div class="col text-right">
                    <div class="custom-control custom-switch">
                        <input name="smtp_tls" type="checkbox" class="custom-control-input" id="smtp_tls" value="1" {{ 'checked' if setting_get('smtp_tls', False) == True }}>
                        <label class="custom-control-label" for="smtp_tls"></label>
                    </div>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_user">SMTP User</label>
                </div>
                <div class="col">
                    <input type="text" class="form-control text-right" name="smtp_user" id="smtp_user" value="{{ setting_get('smtp_user', '') }}" placeholder="" required>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_pass">SMTP Pass</label>
                </div>
                <div class="col">
                    <input type="password" class="form-control text-right" name="smtp_pass" id="smtp_pass" value="{{ '********' if setting_get('smtp_pass', '')|length > 0 }}" placeholder="" required>
                </div>
            </div>

            <div class="form-group row">
                <div class="col">
                    <label for="smtp_sender">SMTP Sender E-mail</label>
                </div>
                <div class="col">
                    <input type="email" class="form-control text-right" name="smtp_sender" id="smtp_sender" value="{{ setting_get('smtp_sender', '') }}" placeholder="from@example.com" required>
                </div>
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-block btn-primary">save</button>
            </div>
        </form>

        <h4>Test E-mail</h4>

        <form action="{{ url_for('config.smtp_test') }}" method="post" class="pb-2">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <div class="form-group row">
                <div class="col">
                    <input name="test_email_recipient" type="email" value="" placeholder="recipient@example.com" class="form-control" required>
                </div>
                <div class="col-3">
                    <a href="#" class="submit-on-click btn btn-info"><i class="fas fa-paper-plane"></i> <span class="ml-2">send</span></a>
                </div>
            </div>
        </form>
    </div>
    <div class="col"></div>
</div>
{% endblock %}